<template>
    <div class="app-container">
        <p>{{ $route.query.metaTitle }}</p>
        <el-divider />
        <el-form ref="ruleForm" :model="form" :rules="rules" label-width="120px">
			<p class="mt15"></p>
            <el-row>
                <el-col :span="12">
				<el-form-item label="指标名称" prop="name">
					<el-input v-model="form.name" placeholder="请输入指标名称，尽量简短" maxlength="50" show-word-limit clearable />
			    	</el-form-item>
			    </el-col>
                <el-col>
                    <el-form-item label="评分内容" prop="remark">
			    	    <el-input v-model="form.remark" type="textarea" maxlength="1000"
			    		    show-word-limit :autosize="{ minRows: 7 }" placeholder="请输入评分内容描述" clearable />
			        </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item label="系统评分" prop="isSystem">
                        <el-input type="hidden" />
			    	    {{ form.isSystem&&form.isSystem=='1'?'是':'否' }}
			        </el-form-item>
                </el-col>
                <el-col style="text-align: center;">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
				    <el-button plain @click="cancel">取 消</el-button>
                </el-col>
            </el-row>
		</el-form>
    </div>
</template>

<script setup name="addThreeLevelIndex">
import { useRoute,useRouter } from "vue-router";
import {saveThreeLevelIndex,updateThreeLevelIndex,detailThreeLevelIndexList} from '@/api/workEvaluation/evaluationStandardSetup/threeLevelIndexLibraryManage.js'
import { onMounted } from "vue";
const { proxy } = getCurrentInstance();
const route = useRoute();
const router = useRouter();
const form = ref({
    name:'',
    remark:'',
})
const rules = ref({
    name: [{ required: true, message: "请输入指标名称", trigger: 'blur', }],
    remark: [{ required: true, message: "请输入评分内容", trigger: 'blur' }],
})
// 确定
function handleBack() {
    closeSelectedTag({ path: '/workEvaluation/evaluationStandardSetup/addThreeLevelIndex', name: 'addThreeLevelIndex' })
}

function closeSelectedTag(view) {
    proxy.$tab.closePage(view).then(() => {
        router.push('/workEvaluation/evaluationStandardSetup/threeLevelIndexLibraryManage');
    })
}
const submitForm =()=>{
	proxy.$refs["ruleForm"].validate(valid => {
	    if (valid) {
	      if (route.query.metaTitle=='修改三级指标') {
	        updateThreeLevelIndex(form.value).then(response => {
	          proxy.$modal.msgSuccess("修改成功");
	          handleBack();
	        });
	      }else{
            saveThreeLevelIndex(form.value).then(response=>{
                proxy.$modal.msgSuccess('新建成功');
                handleBack();
            })
          }
	    }
	});
}
// 取消
const cancel =()=>{
    handleBack();
}
// 获取详情
const detail = ()=>{
    detailThreeLevelIndexList({id:route.query.id}).then(res=>{
        form.value = res.data;
    })
}
onMounted(()=>{
    if(route.query.metaTitle == '修改三级指标'){
        detail();
    }
})

</script>

<style lang="scss" scoped>

</style>